FROM php:8.1-cli

WORKDIR /app

# 使用阿里云镜像源加速apt-get (更新文件路径)
RUN sed -i 's/deb.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list.d/debian.sources && \
    sed -i 's/security.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list.d/debian.sources

# Install system dependencies
RUN apt-get update && apt-get install -y \
    git \
    unzip \
    libzip-dev

# Install Composer
COPY composer.phar /usr/local/bin/composer
RUN chmod +x /usr/local/bin/composer

# Copy composer files and install dependencies
COPY composer.json composer.lock ./
RUN composer update --no-scripts --no-autoloader
RUN composer install --no-scripts --no-autoloader

# Copy the rest of the application
COPY . .

# Generate autoloader
RUN composer dump-autoload --optimize

# Set correct include path
ENV PHP_INCLUDE_PATH="/app"

# Set environment variables from .env file
ENV CTYUN_AK=${CTYUN_AK}
ENV CTYUN_SK=${CTYUN_SK}
ENV CTYUN_REGION_ID=${CTYUN_REGION_ID}

# Run the example
CMD ["php", "example/invoke_workflow/index.php"]